<template>
  <van-nav-bar
    fixed
    left-arrow
    :title="title"
    :right-text="rightText"
    @click-left="onClickLeft"
    @click-right="onClickRight"
  ></van-nav-bar>
</template>

<script lang="ts" setup>
import { useRouter } from 'vue-router';

// import { useRouter } from 'vue-router';
// const router = useRouter();
// const onClickLeft = () => {
//   if (history.state?.back) {
//     router.back();
//   } else {
//     router.push('/');
//   }
// };

// type PropsType = {
//   title?: string;
//   rightText?: string;
// };
// defineProps<PropsType>();

// // const emits = defineEmits(['click-right']);
// const emit = defineEmits<{
//   (e: 'click-right'): void;
// }>();
// // const onClickLeft = () => {};
// const onClickRight = () => {
//   emit('click-right');
// };
const router = useRouter();
type PropsType = {
  title: string;
  rightText: string;
};
defineProps<PropsType>();
const onClickLeft = () => {
  if (history.state.back) {
    router.back();
  } else {
    router.push('/');
  }
};

// const emits = defineEmits(['click-right']);
const emits = defineEmits<{
  (e: 'click-right'): void;
}>();
const onClickRight = () => {
  emits('click-right');
};
</script>

<style lang="scss" scoped>
:deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &__text {
      font-size: 15px;
    }
  }
}
</style>
